package exam.xiecheng.spring.S1;

import java.util.*;

public class Main {

    public static long n;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextLong();
        int pos = String.valueOf(n).length();
        long t = 1;
        long res = 0;
        for (int i=0; i<=pos; ++i) {
            for (int j=0; j<10; ++j) {
                long x = n % t;
                long y = (n - x) * 10 + j * t + x;
                if (y % 7 == 0) {
                    res = y;
                    break;
                }
            }
            if (res != 0)
                break;
            t *= 10;
        }
        System.out.println(res);
    }
}
